package cn.tedu.mvcboot01.controller;

import cn.tedu.mvcboot01.pojo.dto.UserDTO;
import org.openjsse.sun.net.util.IPAddressUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
public class UserController {
    /**服务端获取数据的第一种方式：HttpServletRequest获取*/
    /*
    @RequestMapping("/v1/users/login")
    @ResponseBody
    public String userLogin(HttpServletRequest request){
        String username = request.getParameter("username");
        String password = request.getParameter("password");

        return username + ":" + password;
    }

     */

    /**服务端获取数据的第二种方式：声明参数获取*/
    /*
    @RequestMapping("/v1/users/login")
    @ResponseBody
    // GET: http://localhost:8080/v1/users/login?username=xxx&password=xxx
    // POST: 参数名需要与 <input>标签中name的属性值相同
    public String userLogin(String username, String password){
        return username + "-" + password;
    }

     */

    /**服务端获取数据的第三种方式：声明Pojo类*/
    @RequestMapping("/v1/users/login")
    @ResponseBody
    public String userLogin(UserDTO userDTO){
        String username = userDTO.getUsername();
        String password = userDTO.getPassword();

        return username + "&" + password;
    }
}








